package model;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import model.base.BaseCompany;

@SuppressWarnings("serial")
public class Company extends BaseCompany<Company> {
    public static final Company dao = new Company().dao();
    

	public Company findFirstByName(String name){
        return this.findFirst(" SELECT tc.* FROM t_company tc WHERE tc.name = ? AND tc.isDelete = 0 LIMIT 1 " , name );
    }
	
	public List<Company> findByName(String name){
        return this.find(" SELECT tc.* FROM t_company tc WHERE tc.name LIKE ? AND tc.isDelete = 0 LIMIT 5 " , "%" + name + "%" );
    }
	
	public List<Record> findMarkers(){
        return Db.find(" SELECT tc.id , tc.name AS title , tc.latitude, tc.longitude FROM t_company tc WHERE tc.isDelete = 0  " );
    }

	public boolean isRepeatName(){
		Company ex = Company.dao.findFirstByName( getName() );
		return ( null == getId() && null != ex) || (null != ex && !ex.getId().equals(getId()));
	}
}
